home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 60.zip
/
BS1 part 60
/
C mon v3 d3.adf
/
CMANV3_3.LHA
/
ACE9.lha
/
Devices
/
TimerDevice
/
Example1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-04-27
|
3KB
|
116 lines
/***********************************************************/
/* */
/* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
/* ------------------------------- ------------------ */
/* */
/* Book: ACM Devices Amiga C Club */
/* Chapter: Timer Device Tulevagen 22 */
/* File: Example1.c 181 41 LIDINGO */
/* Author: Anders Bjerin SWEDEN */
/* Date: 92-04-27 */
/* Version: 1.00 */
/* */
/* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
/* */
/* Registered members may use this program freely in their */
/* own commercial/noncommercial programs/articles. */
/* */
/***********************************************************/
/* This example demonstrates how you can use the Timer Device. */
/* The program will be put to sleep for 10 seconds. */
#include <exec/types.h> /* STRPTR */
#include <exec/ports.h> /* struct Message */
#include <exec/memory.h> /* MEMF_PUBLIC */
#include <devices/timer.h> /* TIMERNAME */
/* The reply port: */
struct MsgPort *replymp;
/* The timer request block: */
struct timerequest *tr;
/* When the Timer Device is open this variable is TRUE: */
BOOL not_opened = TRUE;
/* Declare our functions: */
void clean_up();
void main();
void main()
{
/* 1. Get a reply port: */
replymp = (struct MsgPort *)
CreatePort( NULL, 0 );
if( !replymp )
clean_up( "Could not create the reply port!" );
/* 2. Get an extended request block: */
tr = (struct timerequest *)
CreateExtIO( replymp, sizeof( struct timerequest) );
if( !tr )
clean_up( "Could not create the IO!" );
/* 3. Open the Timer Device: */
not_opened = OpenDevice( TIMERNAME, UNIT_VBLANK, tr ,0 );
if( not_opened )
clean_up( "Could not open the Timer Device!" );
/* 4. Set our request: */
tr->tr_node.io_Command = TR_ADDREQUEST; /* Add a request. */
tr->tr_time.tv_secs = 10; /* 10 seconds. */
tr->tr_time.tv_micro = 0; /* 0 micro seconds. */
/* 5. Do our request: (Wait 10 seconds) */
printf( "Good night...\n" );
DoIO( tr );
printf( "Good morning!\n" );
/* Clean up and quit: */
clean_up( "The End!" );
}
void clean_up( text )
STRPTR text;
{
/* Close the Timer Device: */
if( !not_opened )
CloseDevice( tr );
/* Delete the extended request block: */
if( tr )
DeleteExtIO( tr, sizeof( struct timerequest) );
/* Remove the message port: */
if( replymp )
DeletePort( replymp);
/* Print the last message: */
printf( "%s\n", text );
/* Quit: */
exit( 0 );
}